<template>
  <div class="color-container">
    <div class="color-info">
      <template v-for="item in chinaColor" :key="item.pinyin">
        <div class="color-item">
          <div
            class="color-item-box"
            :class="{ 'item-isActive': colorIndexs === item.hex }"
            :style="`background-color: ${item.hex};`"
            @click="handleColor3D(item)"
          ></div>
          <span class="color-item-title">{{ item.name }}</span>
        </div>
      </template>
    </div>
  </div>
</template>

<script setup lang="ts">
import { defineEmits, ref, defineProps } from 'vue'
import { chinaColor } from '@/utils/chinaColor'
import type { IChinaColor } from '@/utils/chinaColor'

const props = defineProps<{ colorIndex?: string }>()
const emits = defineEmits(['handleChooseColor'])

const colorIndexs = ref(props.colorIndex || chinaColor[0].hex)
const handleColor3D = (item: IChinaColor) => {
  colorIndexs.value = item.hex
  emits('handleChooseColor', item)
}
</script>

<style lang="less" scoped>
.color-container {
  width: 100%;
  height: 100%;
}

.color-info {
  width: inherit;
  height: inherit;
  display: flex;

  flex-direction: row;
  flex-wrap: wrap;
  overflow-y: auto;
  &::-webkit-scrollbar {
    width: 5px;
  }
  &::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 1);
    border-radius: 5px;
  }
  &::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1);
  }

  .color-item {
    width: 66px;
    height: 40px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;

    &:hover {
      .color-item-box {
        width: 25px;
        height: 25px;
        box-shadow: 0 0 5px rgba(255, 255, 255, 1);
      }
    }

    .color-item-box {
      width: 20px;
      height: 20px;
      border-radius: 50%;
    }
    .color-item-title {
      color: white;
      font-size: 12px;
      user-select: none;
    }

    .item-isActive {
      width: 25px;
      height: 25px;
    }
  }
}
</style>
